package dp;

/**
 * 相当于是有两个背包的0-1背包问题
 */
public class ds474 {
    public static void main(String[] args) {
        System.out.println(findMaxForm(new String[]{"10","0001","111001","1","0"}, 5, 3));
    }
    public static int findMaxForm(String[] strs, int m, int n) {
        int[][] dp = new int[m + 1][n + 1];
        for (String str : strs) {
            //遍历物品
            //相当于某个物品
            int n_zeros = 0, n_ones = 0;
            char[] ch = str.toCharArray();
            for (char c : ch) {
                if (c == '0')
                    n_zeros++;
                else
                    n_ones++;
            }
            //遍历背包，只不过是双层遍历
            for (int j = m; j >= n_zeros; j--) {
                for (int k = n; k >= n_ones; k--) {
                    dp[j][k] = Math.max(dp[j][k], dp[j - n_zeros][k - n_ones] + 1);
                }
            }
        }
        return dp[m][n];
    }
}
